// ignore_for_file: dangling_library_doc_comments, slash_for_doc_comments
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wan_android_flutter/common_code/utils/date_util.dart';

import '../../../common_code/pages/common_webview.dart';
import '../models/home_tab_list_model.dart';

/*** 
 * @Author: Zhong
 * @Date: 2025-07-23 15:31:23
 * @LastEditors: Zhong zhongxiaodong@eenet.com
 * @LastEditTime: 2025-08-14 18:00:13
 * @FilePath: /wan_android_flutter/lib/module_code/home/widgets/home_page_cell.dart
 * @Description: 
 */

class HomePageCell extends StatefulWidget {
  const HomePageCell({super.key, required this.model});

  final HomeTabListDataDataModel? model;

  @override
  State<HomePageCell> createState() => _HomePageCellState();
}

class _HomePageCellState extends State<HomePageCell> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Get.toNamed(
          CommonWebview.routeName,
          arguments: {'title': widget.model?.title, 'url': widget.model?.link},
        );
      },
      child: Container(
        width: double.infinity,
        decoration: BoxDecoration(color: Colors.white),
        child: _buildItem(),
      ),
    );
  }

  Column _buildItem() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        //第一行
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              CircleAvatar(
                radius: 18,
                backgroundImage: NetworkImage(
                  "https://picsum.photos/id/36/36/",
                ),
                // child: FadeInImage.assetNetwork(
                //   placeholder: "assets/images/login_bg.png",
                //   image: "https://picsum.photos/36/36",
                //   fit: BoxFit.cover,
                // ),
              ),
              Expanded(
                flex: 1,
                child: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 8.0),
                  child: Text(
                    widget.model?.author ?? "匿名",
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: Colors.black,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              ),
              SizedBox(
                width: 80.0,
                child: Text(
                  DateUtil.formatDate(widget.model?.publishTime),
                  textAlign: TextAlign.right,
                  style: TextStyle(fontSize: 12.sp, color: Colors.black),
                ),
              ),
            ],
          ),
        ),

        // 高度随内容改变而改变
        IntrinsicHeight(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.stretch, // 关键点
            children: [
              // 左边
              Expanded(
                flex: 1,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min, // 避免 Column 自身撑满
                  children: [
                    Padding(
                      padding: EdgeInsetsGeometry.symmetric(horizontal: 16),
                      child: Text(
                        widget.model?.title ?? "",
                        style: TextStyle(color: Colors.black, fontSize: 15.sp),
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(
                        horizontal: 16,
                        vertical: 10,
                      ),
                      child: Text(
                        "${widget.model?.chapterName ?? ""} · ${widget.model?.superChapterName ?? ""}",
                        style: TextStyle(fontSize: 12.sp, color: Colors.black),
                      ),
                    ),
                  ],
                ),
              ),
              // 右边
              Container(
                width: 100.w,
                color: Colors.white,
                padding: EdgeInsets.only(bottom: 10, right: 16),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(6),
                  child: FadeInImage.assetNetwork(
                    width: 60.w,
                    height: 60.w,
                    placeholder: "assets/images/empty.png",
                    image: widget.model?.envelopePic ?? "",
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            ],
          ),
        ),

        //分割线
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: Divider(height: 1, thickness: 1, color: Colors.grey[300]),
        ),
      ],
    );
  }
}
